<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script type="text/javascript">
		window.onload = function () {

			var oDiv = document.getElementById('div1');


			var iLeft = 0;
			var iSpeed = 3;
			/*
			var timer = setInterval(moving,30);
			function moving(){
				iLeft += 3;
				oDiv.style.left = iLeft + 'px';
			}
			*/
			var timer = setInterval(function () {

				iLeft += iSpeed;
				oDiv.style.left = iLeft + 'px';

				if (iLeft > 700) {
					iSpeed = -3;
					//clearInterval(timer);
				}
				if (iLeft < 0) {
					iSpeed = 3;
					//clearInterval(timer);
				}
			}, 30);
		}
	</script>
	<style type="text/css">
		.box {
			width: 200px;
			height: 200px;
			background-color: gold;
			position: absolute;
			left: 0;
			top: 100px;
		}
	</style>
</head>

<body>
	<div id="div1" class="box"></div>
</body>

</html>